package com.mimc.controller.admin;

import com.jfinal.aop.Inject;
import com.jfinal.core.paragetter.Para;
import com.jfinal.plugin.activerecord.Page;
import com.mimc.core.model.SysDictData;
import com.mimc.core.service.SysDictDataService;
import com.mimc.framework.domain.AjaxResult;
import com.mimc.framework.jwt.AdminTokenUtils;
import io.jboot.db.model.Columns;
import io.jboot.web.controller.JbootController;
import io.jboot.web.controller.annotation.RequestMapping;

import java.util.Date;
@RequestMapping("/admin/sys/dict/data")
public class SysDictDataController extends JbootController {
    @Inject
    private SysDictDataService sysDictDataService;
    public AjaxResult lists(String dictType){
        Integer page=getInt("page",1);
        Integer pageSize=getInt("pageSize",15);
        Page<SysDictData> list=sysDictDataService.paginateByColumns(page,pageSize, Columns.create("dict_type",dictType),"dict_sort asc");
        return AjaxResult.success("成功",list);
    }

    public AjaxResult add(@Para("") SysDictData sysDictData){
        sysDictData.setCreateBy(AdminTokenUtils.getUserName());
        sysDictData.setCreateTime(new Date());
        sysDictDataService.save(sysDictData);
        return AjaxResult.success("添加成功");
    }

    public AjaxResult update(@Para("") SysDictData sysDictData){
        sysDictData.setUpdateBy(AdminTokenUtils.getUserName());
        sysDictData.setUpdateTime(new Date());
        sysDictDataService.update(sysDictData);
        return AjaxResult.success("更新成功");
    }

    public AjaxResult delete(Long dictCode){
        SysDictData sysDictData=sysDictDataService.findById(dictCode);
        sysDictDataService.delete(sysDictData);
        return AjaxResult.success("删除成功");
    }
}
